﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Model;
using IHISCETeim.Library;
using IHISCETeim.BLL;

namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class ODailyAdd : PageBase
    {
        #region

        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.新增 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "ODailyList";
            }
        }

        #endregion


        protected int DefaultDailyCategory
        {
            get
            {
                return GetRequestValue<int>("DailyCategory",0);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "adddaily")
            {
                addmenu();
            }
        }

        protected void addmenu()
        {
            string UserName = GetRequestValue<string>("dwz.orgLookup.UserName","");
            string[] WorkDates = GetRequestValue<string>("WorkDate", "").Split(new char[]{','});
            string[] GongWeis = GetRequestValue<string>("GongWei", "").Split(new char[]{','});
            string[] JobCodes = GetRequestValue<string>("JobCode", "").Split(new char[]{','});
            string[] SerialNumbers = GetRequestValue<string>("SerialNumber", "").Split(new char[]{','});
            string[] TaskTimes = GetRequestValue<string>("TaskTime", "").Split(new char[]{','});
            string[] Remarks = GetRequestValue<string>("Remark", "").Split(new char[]{','});

            int DailyCategory = GetRequestValue<int>("DailyCategory", 0);

            List<OJobContentInfo> allJobCon = OJobController.GetALLJobContent();

            for(int index=0;index<WorkDates.Count();index++)
            {
                ODailyInfo obj = new ODailyInfo();
                
                obj.UserName = UserName;
                obj.WorkDate =Convert.ToDateTime(WorkDates[index]);
                obj.GongWei = GongWeis[index].ToUpper();
                obj.JobCode = JobCodes[index].ToUpper();

                OJobContentInfo tempobj= allJobCon.First<OJobContentInfo>(e => e.JobCode == obj.JobCode);

                obj.JobTitle = tempobj.JobTitle ;
                obj.SerialNumber = SerialNumbers[index].ToUpper();
                obj.TaskTime =Convert.ToDecimal( TaskTimes[index]);
                obj.Remark = Remarks[index];

                obj.DailyCategory = DailyCategory;

                obj.MachineType =obj.DailyCategory==1? GetMacTypeBySerialNumber(obj.SerialNumber):"";

                ODailyController.Add(obj);
                this.AddLog(Permission.新增, null, obj);
            }

            SuccessJson("新增成功", "ODailyAdd", "MacModel/ODailyAdd.aspx?DailyCategory="+  DefaultDailyCategory.ToString());
            //ODailyInfo obj = Request.SerializableObject<OMenuInfo>();
            //string x = Request["PermissionTag"];
            //if (string.IsNullOrEmpty(x))
            //    AlertJson("请先选择页面功能权限.");
            //if (OMenuController.AddOMenu(obj, x))
            //    SuccessJson("添加成功");
            //else
            //    ErrorJson("添加失败");
        }
    }
}